home *** CD-ROM | disk | FTP | other *** search
-
- /*+
- * File: dosb2t.c
- * Description:
- * dosb2t is a filter.
- * dosb2t processes i_files or the standard input.
- * dosb2t writes to o_file or standard output.
- *
- * Converts a DOS binary file to text file.
- * Replaces <lf> with <cr><lf>.
- *
- * Usages:
- * dosb2t [-o] <o_file> <i_files>
- *
- *
- * Author: Mohsen Banan.
- *
- * This program is public domain software, no warranty intended or
- * implied.
- * General permission to copy or modify, but not for profit, is
- * hereby granted.
- *
- *
- * Functions:
- *
- *
- * Audit Trail: $Log: dosb2t.c,v $
- * Revision 1.1 85/08/28 08:38:24 mohsen
- * original posting to the net
- *
- *
- *
- -*/
-
- #ifdef RCS_VER
- static char *rcs = "$Header: dosb2t.c,v 1.1 85/08/28 08:38:24 mohsen Exp $";
- #endif
-
- /* #includes */
- #include "mbstd.h"
- #include <stdio.h>
- #include <ctype.h>
- #include <fcntl.h>
- #ifdef unix
- #include "msc3.h"
- #endif
-
- /* #defines */
-
- /* external variables */
-
- /* referenced external function declarations */
-
- /* internal function declarations */
- PUBLIC VOID dosb2t();
- PUBLIC VOID cant_open();
- STATIC VOID usage();
-
- /* global variables */
-
- /* static variables */
- STATIC CHAR * prog_name;
-
-
- INT
- main (argc, argv)
- INT argc;
- CHAR * argv[];
- {
- dosb2t(argc, argv);
- }
-
-
- /*<
- * Function:dosb2t
- * Description:
- *
- * Returns:
- * VOID
- *
- >*/
- PUBLIC VOID
- dosb2t (argc,argv)
- INT argc;
- CHAR * argv[];
- {
- FILE * i_fp;
- FILE * o_fp;
-
- INT i;
- INT c;
-
- i_fp = stdin;
- o_fp = stdout;
- prog_name = argv[0];
- for (i=1; i<argc; ++i) {
- if (*argv[i] == '-') {
- /* To handle concatenated switches */
- INT j;
- j=i;
- while (*(++argv[j])) {
- switch (*argv[j]) {
- case 'o':
- case 'O':
- if ( !(o_fp = fopen(argv[++i], "w")) ) {
- cant_open (prog_name, argv[i]);
- exit (1);
- }
- break;
- default:
- usage();
- exit(1);
- } /* switch (*argv[j]) */
- } /* while (*(++argv[j])) */
- } /* if '-' */
- else {
- if (!(i_fp = fopen (argv[i], "r"))) {
- cant_open (prog_name, argv[i]);
- exit (1);
- }
- setmode (fileno(i_fp), O_BINARY);
- setmode (fileno(o_fp), O_TEXT);
- while (( c = getc (i_fp)) != EOF) {
- putc (c, o_fp);
- }
- fclose (i_fp);
- }
- } /* for i<argc */
- fclose (o_fp);
- exit (0);
- }
-
- PUBLIC VOID
- cant_open (prog_name,filename)
- CHAR * prog_name;
- CHAR * filename;
- {
- fprintf (stderr, "%s :can not open %s \n", prog_name, filename);
- }
-
- STATIC VOID
- usage ()
- {
- fprintf (stderr, "Usage: %s [-o] <o_file> <i_files> \n", prog_name);
- }
-
-
-